
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>redis04 String数据类型详解 · Redis</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="<yangxin19970404@163.com>">
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="redis05 List数据类型详解.html" />
    
    
    <link rel="prev" href="redis03 redis基础知识.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="redis01 redis开始.html">
            
                <a href="redis01 redis开始.html">
            
                    
                    redis01 redis开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="redis02 redis安装.html">
            
                <a href="redis02 redis安装.html">
            
                    
                    redis02 redis安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="redis03 redis基础知识.html">
            
                <a href="redis03 redis基础知识.html">
            
                    
                    redis03 redis基础知识
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5" data-path="redis04 String数据类型详解.html">
            
                <a href="redis04 String数据类型详解.html">
            
                    
                    redis04 String数据类型详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="redis05 List数据类型详解.html">
            
                <a href="redis05 List数据类型详解.html">
            
                    
                    redis05 List数据类型详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="redis06 Set数据类型详解.html">
            
                <a href="redis06 Set数据类型详解.html">
            
                    
                    redis06 Set数据类型详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="redis07 Hash数据类型详解.html">
            
                <a href="redis07 Hash数据类型详解.html">
            
                    
                    redis07 Hash数据类型详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="redis08 Zset数据类型详解.html">
            
                <a href="redis08 Zset数据类型详解.html">
            
                    
                    redis08 Zset数据类型详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="redis09 Geospatial地理位置详解.html">
            
                <a href="redis09 Geospatial地理位置详解.html">
            
                    
                    redis09 Geospatial地理位置详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="redis10 Hyperloglog基数统计详解.html">
            
                <a href="redis10 Hyperloglog基数统计详解.html">
            
                    
                    redis10 Hyperloglog基数统计详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="redis11 Bitmap位图场景详解.html">
            
                <a href="redis11 Bitmap位图场景详解.html">
            
                    
                    redis11 Bitmap位图场景详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="redis12 Redis事务操作.html">
            
                <a href="redis12 Redis事务操作.html">
            
                    
                    redis12 Redis事务操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="redis13 Redis实现乐观锁.html">
            
                <a href="redis13 Redis实现乐观锁.html">
            
                    
                    redis13 Redis实现乐观锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="redis14 Jedis.html">
            
                <a href="redis14 Jedis.html">
            
                    
                    redis14 Jedis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="redis15 springBoot整合redis.html">
            
                <a href="redis15 springBoot整合redis.html">
            
                    
                    redis15 springBoot整合redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="redis16 RedisUtil.html">
            
                <a href="redis16 RedisUtil.html">
            
                    
                    redis16 RedisUtil
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="redis17 Redis.config详解.html">
            
                <a href="redis17 Redis.config详解.html">
            
                    
                    redis17 Redis.config详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="redis18 Redis持久化RDB.html">
            
                <a href="redis18 Redis持久化RDB.html">
            
                    
                    redis18 Redis持久化RDB
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="redis19 Redis持久化AOF.html">
            
                <a href="redis19 Redis持久化AOF.html">
            
                    
                    redis19 Redis持久化AOF
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="redis20 Redis发布订阅.html">
            
                <a href="redis20 Redis发布订阅.html">
            
                    
                    redis20 Redis发布订阅
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="redis21 Redis主动复制.html">
            
                <a href="redis21 Redis主动复制.html">
            
                    
                    redis21 Redis主动复制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="redis21 Redis哨兵模式.html">
            
                <a href="redis21 Redis哨兵模式.html">
            
                    
                    redis21 Redis哨兵模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="redis22 Redis缓存穿透和雪崩.html">
            
                <a href="redis22 Redis缓存穿透和雪崩.html">
            
                    
                    redis22 Redis缓存穿透和雪崩
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >redis04 String数据类型详解</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="string&#x7C7B;&#x578B;">String&#x7C7B;&#x578B;</h3>
<hr>
<blockquote>
<p>&#x4F8B;&#x5982;:</p>
<pre><code class="lang-shell">    127.0.0.1:6379&gt; set name yang
    OK
    127.0.0.1:6379&gt; get name
    &quot;yang&quot;
    127.0.0.1:6379&gt; exists name   # &#x662F;&#x5426;&#x5B58;&#x5728;
    (integer) 1
    127.0.0.1:6379&gt; append name &quot;xin&quot;  # &#x8FFD;&#x52A0;&#x5B57;&#x7B26;&#x4E32;
    (integer) 7
    127.0.0.1:6379&gt; get name
    &quot;yangxin&quot;
    127.0.0.1:6379&gt; strlen name   # &#x83B7;&#x53D6;&#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;
    (integer) 7
    127.0.0.1:6379&gt; append name &quot;xin111111&quot;
    (integer) 16
    127.0.0.1:6379&gt; get name
    &quot;yangxinxin111111&quot;
</code></pre>
<p>&#x81EA;&#x589E;&#x81EA;&#x51CF;</p>
</blockquote>
<pre><code class="lang-shell">    127.0.0.1:6379&gt; set view 0
    OK
    127.0.0.1:6379&gt; get view
    &quot;0&quot;
    127.0.0.1:6379&gt; incr view  # &#x81EA;&#x589E;,&#x6D4F;&#x89C8;&#x5668;+1
    (integer) 1
    127.0.0.1:6379&gt; incr view
    (integer) 2
    127.0.0.1:6379&gt; incr view
    (integer) 3
    127.0.0.1:6379&gt; get view
    &quot;3&quot;
    127.0.0.1:6379&gt; decr view
    (integer) 2
    127.0.0.1:6379&gt; incr view
    (integer) 3
    127.0.0.1:6379&gt; incr view
    (integer) 4
    127.0.0.1:6379&gt; incrby view 10  # &#x8BBE;&#x7F6E;&#x6B65;&#x957F;
    (integer) 14
    127.0.0.1:6379&gt; decrby view 5
    (integer) 9
    127.0.0.1:6379&gt;
    ########################################################
    127.0.0.1:6379&gt; getrange view 0 -1  # &#x622A;&#x53D6;&#x5B57;&#x7B26;&#x4E32;
    &quot;9&quot;
    127.0.0.1:6379&gt; 
    ########################################################
    127.0.0.1:6379&gt; get name
    &quot;yxxxxinxin111111&quot;
    127.0.0.1:6379&gt; setrange name 5 YYY  # &#x66FF;&#x6362;&#x5B57;&#x7B26;&#x4E32;,&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x5F00;&#x59CB;&#x7684;&#x5B57;&#x7B26;&#x4E32;
    (integer) 16
    127.0.0.1:6379&gt; get name
    &quot;yxxxxYYYin111111&quot;
    127.0.0.1:6379&gt;
</code></pre>
<blockquote>
<p>&#x9AD8;&#x7AEF;&#x7684;</p>
</blockquote>
<pre><code class="lang-shell">    # setex (set with expire) : &#x8BBE;&#x7F6E;&#x8FC7;&#x671F;&#x65F6;&#x95F4;
    # setnx (set if not exist) : &#x4E0D;&#x5B58;&#x5728;&#x518D;&#x8BBE;&#x7F6E;(&#x5728;&#x5206;&#x5E03;&#x5F0F;&#x9501;&#x65F6;&#x5E38;&#x4F7F;&#x7528;)
    127.0.0.1:6379&gt; setex key3 30 &quot;hello&quot; 
    OK
    127.0.0.1:6379&gt; ttl key3
    (integer) 23
    127.0.0.1:6379&gt; setnx mykey &quot;redis&quot;
    (integer) 1
    127.0.0.1:6379&gt; setnx mykey &quot;yang&quot;  # &#x5982;&#x679C;key&#x5B58;&#x5728;,&#x5219;&#x8BBE;&#x7F6E;&#x5931;&#x8D25;
    (integer) 0
    127.0.0.1:6379&gt; keys *
    1) &quot;view&quot;
    2) &quot;mykey&quot;
    3) &quot;name&quot;
    127.0.0.1:6379&gt; get mykey   
    &quot;redis&quot;
    127.0.0.1:6379&gt;
</code></pre>
<blockquote>
<p>&#x6279;&#x91CF;&#x8BBE;&#x7F6E;&#x6279;&#x91CF;&#x83B7;&#x53D6;</p>
</blockquote>
<pre><code class="lang-shell">    127.0.0.1:6379&gt; get mykey  # &#x540C;&#x65F6;&#x8BBE;&#x7F6E;&#x591A;&#x4E2A;&#x503C;
    &quot;redis&quot;
    127.0.0.1:6379&gt; mset k1 v1 k2 v2
    OK
    127.0.0.1:6379&gt; mget k1 k2
    1) &quot;v1&quot;
    2) &quot;v2&quot;
</code></pre>
<blockquote>
<p>&#x8BBE;&#x7F6E;&#x5BF9;&#x8C61;</p>
</blockquote>
<p><img src="./imgs/&#x5FAE;&#x4FE1;&#x622A;&#x56FE;_20210318110836.png" alt=""></p>
<p><img src="./imgs/&#x5FAE;&#x4FE1;&#x622A;&#x56FE;_20210318111000.png" alt=""></p>
<p><strong>&#x6570;&#x636E;&#x7ED3;&#x6784;&#x662F;&#x76F8;&#x901A;&#x7684;,</strong>
String&#x7C7B;&#x578B;&#x7684;&#x4F7F;&#x7528;&#x573A;&#x666F;: value&#x9664;&#x4E86;&#x662F;&#x6211;&#x4EEC;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x8FD8;&#x53EF;&#x4EE5;&#x4F7F;&#x6211;&#x4EEC;&#x7684;&#x6570;&#x5B57;!</p>
<ul>
<li>&#x8BA1;&#x6570;&#x5668;</li>
<li>&#x7EDF;&#x8BA1;&#x591A;&#x5355;&#x4F4D;&#x7684;&#x6570;&#x91CF;</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="redis03 redis基础知识.html" class="navigation navigation-prev " aria-label="Previous page: redis03 redis基础知识">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="redis05 List数据类型详解.html" class="navigation navigation-next " aria-label="Next page: redis05 List数据类型详解">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"redis04 String数据类型详解","level":"1.5","depth":1,"next":{"title":"redis05 List数据类型详解","level":"1.6","depth":1,"path":"redis05 List数据类型详解.md","ref":"redis05 List数据类型详解.md","articles":[]},"previous":{"title":"redis03 redis基础知识","level":"1.4","depth":1,"path":"redis03 redis基础知识.md","ref":"redis03 redis基础知识.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"<yangxin19970404@163.com>","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Redis","language":"zh-hans","gitbook":"3.2.3","description":"Redis > 缓存技术"},"file":{"path":"redis04 String数据类型详解.md","mtime":"2021-04-17T07:00:09.674Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-04-17T07:48:08.480Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

